package com.ibeetl.admin.core.util.beetl;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.math.NumberUtils;
import org.beetl.core.Context;
import org.beetl.core.Function;
import org.beetl.sql.core.SQLManager;
import org.beetl.sql.core.query.LambdaQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.ibeetl.admin.core.entity.CoreConfig;
import com.ibeetl.admin.core.service.CoreZanService;

/**
 * 点赞 获得某个文章的点赞数
 * 
 * 第一个参数是articleId,第二个参数是type
 */
@Component
public class ZanFunction implements Function {

	@Autowired
	CoreZanService zanService;
	@Autowired SQLManager sqlManager;
	
	/**
	 * 第一个参数是articleId
	 * 第二个参数是type字符
	 */
	public Object call(Object[] paras, Context ctx) {
		if (paras.length == 1) {
			Integer count = this.zanService.getZanByArticleId(NumberUtils.toLong(String.valueOf(paras[0])),null);
			return count;
		}
		if (paras.length == 2) {
			Integer count = this.zanService.getZanByArticleId(NumberUtils.toLong((String)paras[0]),(String)paras[1]);
			if (count == null || count == 0) count = 0;
			return count;
		}
		return 0;
	}
	
	

}
